<template>
	<div class="tab-bar">
		<div class="tab-bar-item" v-for="(item, index) in tabList" :key="index" @click="switchTab(item)">
			<div class="tab-bar-icon"><image class="img" :src="item.tabBar ? (active === index ? item.selectedIconPath : item.iconPath) : item.iconPath"></image></div>
			<div class="tab-bar-text">{{ item.text }}</div>
		</div>
	</div>
</template>

<script>
export default {
	data() {
		return {
			active: 0,
			tabList: [
				{
					pagePath: '/pages/friend_list/friend_list',
					text: '动态',
					iconPath: '/static/dongtai-before.png',
					selectedIconPath: '/static/dongtai-before.png',
					tabBar: true
				},
				{
				  pagePath: '/pages/index/index',
				  text: '聊天',
				  iconPath: '/static/liaotian-before.png',
				  selectedIconPath: '/static/liaotian-before.png',
				  tabBar: true
				}
			]
		};
	},
	methods: {
		switchTab(item) {
			if (item.tabBar) {
				let index = this.tabList.findIndex(i => i.pagePath === item.pagePath);
				if (index !== -1) {
					this.active = index;
					console.log("2")
					console.log(item.pagePath)
					uni.switchTab({
						url: item.pagePath
					});
				}
			}
		}
	}
};
</script>

<style>
.img {
	width: 110rpx;
	height: 82rpx;
}
.tab-bar {
	position: fixed;
	/* bottom: 0; */
	margin-top: 1250rpx;
	left: 0;
	width: 100%;
	height: 95px;
	z-index: 9999;
	background-color: #fff;
	display: flex;
	justify-content: space-evenly;
	align-items: center;
	box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
}

.tab-bar-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	font-size: 12px;
	color: #666;
}

.tab-bar-icon {
	/* width: 24rpx;
	height: 24rpx;
	margin-bottom: 2px; */
}

.tab-bar-text {
  font-size: 12px;
  margin-bottom: 40rpx;
}
</style>
